package cn.stylefeng.guns.modular.redline.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.modular.redline.entity.Redline;
import cn.stylefeng.guns.modular.redline.model.params.RedlineParam;
import cn.stylefeng.guns.modular.redline.service.RedlineService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.kernel.model.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;


/**
 * 红色路线控制器
 *
 * @author Dong
 * @Date 2023-10-12 21:02:55
 */
@Controller
@RequestMapping("/redline")
public class RedlineController extends BaseController {

    private String PREFIX = "/redline";

    @Autowired
    private RedlineService redlineService;

    /**
     * 跳转到主页面
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/redline.html";
    }

    /**
     * 新增页面
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/add")
    public String add() {
        return PREFIX + "/redline_add.html";
    }

    /**
     * 编辑页面
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/redline_edit.html";
    }

    /**
     * 新增接口
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(RedlineParam redlineParam) {
        redlineParam.setCreateTime(DateUtil.format(new DateTime(),"yyyy-MM-dd HH:mm:ss"));
        this.redlineService.add(redlineParam);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(RedlineParam redlineParam) {
        this.redlineService.update(redlineParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(RedlineParam redlineParam) {
        Redline rl = redlineService.getById(redlineParam.getId());
        rl.setIsdel(1);
        this.redlineService.updateById(rl);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(RedlineParam redlineParam) {
        Redline detail = this.redlineService.getById(redlineParam.getId());
        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author Dong
     * @Date 2023-10-12
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(RedlineParam redlineParam) {
        return this.redlineService.findPageBySpec(redlineParam);
    }
    @ResponseBody
    @RequestMapping("/listall")
    public ResponseData listall() {
        return ResponseData.success(this.redlineService.list(new QueryWrapper<Redline>().eq("isdel",0)));
    }

}


